package com.gm;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by Administrator on 13-12-23.
 */
public class TextFileTest {
    public static void main(String[] args) {
        Employee[] emps=new Employee[3];

        emps[0]=new Employee("sxx",400,1985,6,20);
        emps[1]=new Employee("sxx2",400,1987,4,20);
        emps[2]=new Employee("sxx",400,1989,6,2);

        PrintWriter writer= null;
        try {
            writer = new PrintWriter("Employee.dat");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        writeData(emps,writer);
        writer.close();

        Scanner scanner= null;
        try {
            scanner = new Scanner(new FileReader("Employee.dat"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        Employee[] newEmp=readData(scanner);

        for(Employee e: newEmp) {
            System.out.println(e);
        }
    }

    static void writeData(Employee[] emps,PrintWriter out){
        out.println(emps.length);

        for(Employee emp:emps){
            emp.writeData(out);
        }
    }

    static Employee[] readData(Scanner in){
        int n=in.nextInt();
        in.nextLine();

        Employee[] emps=new Employee[n];

        for(int i=0;i<n;i++){
            emps[i]=new Employee();
            emps[i].readData(in);
        }

        return emps;
    }
}
